package zuo.from0516.basic2020.class03;


public class Code02_DeleteGivenValue {
    public static class Node{
        int value;
        Node next;
        Node(int data){
            this.value = data;
        }
    }

    public static Node removeValue(Node head, int target){
        while (head != null){
            if (head.value != target){
                break;
            }
            head = head.next;
        }

        Node cur = head;
        Node pre = head;

        while (cur != null){
            if(cur.value == target){
                pre.next = cur.next;

            }else{
                pre = cur;
            }
            cur = cur.next;
        }

        return head;
    }

    //删除有序数组的重复项，返回新数组的长度
    public static void main(String[] args) {

    }

    public static int delete(int[] arr){
        int i = 0;
        for (int j=1; j < arr.length; i++) {
            if (arr[j] != arr[j-1]){
                arr[i] = arr[j];
                i++;
            }
            j++;
        }
        return i;
    }

  
}
